<ui:composition xmlns="http://www.w3.org/1999/xhtml"
    xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:c="http://java.sun.com/jstl/core"
	xmlns:af="http://myfaces.apache.org/trinidad"
	xmlns:afh="http://myfaces.apache.org/trinidad/html"
    xmlns:ppc="http://www.sungard.de/carnot/web/portal-plugin/common">
    
    <c:if test="#{empty fieldType}">
      <c:set var="fieldType" value="#{fieldModel.type}"/>
    </c:if>

<c:if test="#{fieldType eq 'String'}">
	<af:inputText
        valueChangeListener="#{filterField.valueChanged}"
        onkeyup="partialSubmit_afterEnter(event, form, this.id);"
		simple="true"
		value="#{fieldModel.stringValue}"
		shortDesc="#{commonMsg.enterFilterValue}"
		contentStyle="font-size: x-small; border-width: thin; width: 95%;" 
        rendered="#{fieldType eq 'String'}">
    </af:inputText>
</c:if>

<c:if test="#{fieldType eq 'Structured'}">
    <af:inputText
        valueChangeListener="#{filterField.valueChanged}"
        onkeyup="partialSubmit_afterEnter(event, form, this.id);"
        simple="true"
        value="#{fieldModel.stringValue}"
        shortDesc="#{commonMsg.enterFilterValue}"
        contentStyle="font-size: x-small; border-width: thin; width: 95%;"
        rendered="#{fieldType eq 'Structured'}">
    </af:inputText>
</c:if>

<c:if test="#{fieldType eq 'Boolean'}">
<ui:remove>
	<af:selectBooleanCheckbox selected="#{fieldModel.booleanValue}"
        valueChangeListener="#{filterField.valueChanged}"
		shortDesc="#{commonMsg.enterFilterValue}"
        autoSubmit="true"
		contentStyle="font-size: x-small; border-width: thin;"/>
</ui:remove>
</c:if>

<c:if test="#{fieldType eq 'Long'}">
	<af:inputText
        valueChangeListener="#{filterField.valueChanged}"
        onkeyup="partialSubmit_afterEnter(event, form, this.id);"
		simple="true"
		value="#{fieldModel.longValue}"
		shortDesc="#{commonMsg.enterFilterValue}"
		contentStyle="font-size: x-small; border-width: thin; width: 95%;">
		<af:convertNumber/>
	</af:inputText>
</c:if>

<c:if test="#{fieldType eq 'Priority'}">
    <!-- Workaround: JSF wouldn't submit the default value. 
             So we set the selected index to the disabled value 
             if the default value is selected. -->
    <af:selectOneChoice
        valueChangeListener="#{filterField.valueChanged}"
        autoSubmit="true" immediate="true" simple="true" valuePassThru="true"
        onchange="if(this.value == '') {this.selectedIndex = 4;}"
        onmouseout="if(this.selectedIndex == 4) {this.selectedIndex = 0;}"
        value="#{fieldModel.longValue}" unselectedLabel="#{commonMsg.allPriorities}"
        shortDesc="#{commonMsg.chooseFilterValue}"
        contentStyle="font-size: x-small; border-width: thin; width: 95%;">
        <af:selectItem label="#{ppc:priorityLabel(1)}" value="1"/>
        <af:selectItem label="#{ppc:priorityLabel(0)}" value="0"/>
        <af:selectItem label="#{ppc:priorityLabel(-1)}" value="-1"/>
        <af:selectItem label="" value="2" disabled="true"/>
    </af:selectOneChoice>
</c:if>

<c:if test="#{fieldType eq 'Double'}">
	<af:inputText
        valueChangeListener="#{filterField.valueChanged}"
        onkeyup="partialSubmit_afterEnter(event, form, this.id);"
		simple="true"
		value="#{fieldModel.doubleValue}"
		shortDesc="#{commonMsg.enterFilterValue}"
		contentStyle="font-size: x-small; border-width: thin; width: 95%;">
	</af:inputText>
</c:if>

<c:if test="#{fieldType eq 'TimeStamp'}">
    <af:panelGroupLayout styleClass="timeStampFilterGroup" layout="vertical">
        <af:panelPopup triggerType="click" modal="true" title="#{commonMsg.timeFilter}"
            xoffset="1" yoffset="2">
            <f:facet name="trigger">
                <af:panelGroupLayout layout="horizontal">
                    <af:icon name="popupFilter" />
                    <af:outputText
                        value="#{fieldModel.filterLabel}"
                        styleClass="timeStampFilterText">
                    </af:outputText>
                </af:panelGroupLayout>
            </f:facet>
            <af:panelFormLayout>
                <af:inputDate columns="17" label="#{fieldModel.fromTimeField.label}"
                    value="#{fieldModel.fromTimeField.dateValue}"
                    valueChangeListener="#{filterField.valueChanged}"
                    onkeyup="submitForm_afterEnter(event, form)"
                    contentStyle="font-size: x-small; border-width: thin;">
                    <af:convertDateTime type="both" pattern="#{dateUtils.dateFormatter}" />
                </af:inputDate>
                <af:inputDate columns="17" label="#{fieldModel.toTimeField.label}"
                    value="#{fieldModel.toTimeField.dateValue}"
                    valueChangeListener="#{filterField.valueChanged}"
                    onkeyup="submitForm_afterEnter(event, form)"
                    contentStyle="font-size: x-small; border-width: thin;">
                    <af:convertDateTime type="both" pattern="#{dateUtils.dateFormatter}" />
                </af:inputDate>
                <af:spacer height="3" />
            </af:panelFormLayout>
            <af:panelButtonBar halign="center" styleClass="filterPopupButtonBar">
                <af:commandLink id="applyTimeFilter"
                    text="#{commonMsg.applyLabel}"
                    action="#{fieldModel.onApply}"/>
                <af:commandLink id="resetTimeFilter" immediate="false"
                    text="#{commonMsg.resetFilter}"
                    action="#{fieldModel.onReset}"/>
            </af:panelButtonBar>
            <af:spacer height="3" />
        </af:panelPopup>
    </af:panelGroupLayout>
</c:if>

<c:if test="#{fieldType eq 'ActivityName'}">
    <af:panelGroupLayout layout="vertical">
        <af:panelPopup triggerType="click"
            modal="true" title="#{commonMsg.activityFilter}"
            xoffset="1" yoffset="2">
            <f:facet name="trigger">
                <af:panelGroupLayout layout="horizontal">
                    <af:icon name="popupFilter" />
                    <af:outputText
                        value="#{fieldModel.filterLabel}" shortDesc="#{fieldModel.tooltip}"
                        styleClass="activityNameFilterText">
                    </af:outputText>
                </af:panelGroupLayout>
            </f:facet>
            <af:panelFormLayout>
                <af:inputText id="activityNameFilterInput" label="#{commonMsg.activityNameFilter}:"
                    value="#{fieldModel.activityNameFilter}" shortDesc="#{commonMsg.activityNameFilterTooltip}"
                    onkeyup="return partialSubmit_afterEnter(event, form, this.id);"/>
                <af:panelAccordion id="activityNameFilter" partialTriggers="activityNameFilterInput"
                    discloseMany="false" discloseNone="true">
                    <c:forEach var="pd" items="#{fieldModel.processDefinitions}" varStatus="state">
                        <af:showDetailItem text="#{pd.processName}"
                            disclosed="#{state.index eq 0 ? true : false}">
                            <af:panelFormLayout>
                                <af:selectManyCheckbox autoSubmit="true" layout="vertical" value="#{pd.selectedActivities}">
                                    <f:selectItems value="#{pd.allActivities}"/>
                                </af:selectManyCheckbox>
                            </af:panelFormLayout>
                        </af:showDetailItem>
                    </c:forEach>
                </af:panelAccordion>
                <af:spacer height="3" />
            </af:panelFormLayout>
            <af:panelButtonBar halign="center" styleClass="filterPopupButtonBar">
                <af:commandLink id="applyActivityNameFilter"
                    text="#{commonMsg.applyLabel}"
                    action="#{fieldModel.onApply}"/>
                <af:commandLink id="resetActivityNameFilter" immediate="false"
                    text="#{commonMsg.resetFilter}"
                    action="#{fieldModel.onReset}"/>
            </af:panelButtonBar>
            <af:spacer height="3" />
        </af:panelPopup>
    </af:panelGroupLayout>
</c:if>

</ui:composition>